home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / redalert.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  245 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. unsigned char *redalert_backram;
  13. unsigned char *redalert_spriteram1;
  14. unsigned char *redalert_spriteram2;
  15. unsigned char *redalert_characterram;
  16.  
  17. static unsigned char redalert_dirtyback[0x400];
  18. static unsigned char redalert_dirtycharacter[0x100];
  19. static unsigned char redalert_backcolor[0x400];
  20.  
  21. /* There might be a color PROM that dictates this? */
  22. /* These guesses are based on comparing the color bars on the test
  23.    screen with the picture in the manual */
  24. static unsigned char color_lookup[] = {
  25.     1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,
  26.     1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,
  27.     3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  28.     1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,
  29.     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  30.     1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,
  31.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  32.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  33.  
  34.     1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,
  35.     2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  36.     2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
  37.     1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,
  38.     3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  39.     3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  40.     3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  41.     3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
  42. };
  43.  
  44. static int backcolor;
  45.  
  46. WRITE_HANDLER( redalert_c040_w )
  47. {
  48.     /* Only seems to load D0-D3 into a flip-flop. */
  49.     /* D0/D1 seem to head off to unconnected circuits */
  50.     /* D2 connects to a "NL" line, and NOTted to a "NH" line */
  51.     /* D3 connects to a "YI" line */
  52. }
  53.  
  54. WRITE_HANDLER( redalert_backcolor_w )
  55. {
  56.     /* Only seems to load D0-D2 into a flip-flop. */
  57.     /* Outputs feed into RAM which seems to feed to RGB lines. */
  58.     backcolor = data & 0x07;
  59. }
  60.  
  61.  
  62. /***************************************************************************
  63. redalert_backram_w
  64. ***************************************************************************/
  65.  
  66. WRITE_HANDLER( redalert_backram_w )
  67. {
  68.     int charnum;
  69.  
  70.     charnum = offset / 8 % 0x400;
  71.  
  72.     if ((redalert_backram[offset] != data) ||
  73.         (redalert_backcolor[charnum] != backcolor))
  74.     {
  75.         redalert_dirtyback[charnum] = 1;
  76.         dirtybuffer[charnum] = 1;
  77.         redalert_backcolor[charnum] = backcolor;
  78.  
  79.         redalert_backram[offset] = data;
  80.     }
  81. }
  82.  
  83. /***************************************************************************
  84. redalert_spriteram1_w
  85. ***************************************************************************/
  86.  
  87. WRITE_HANDLER( redalert_spriteram1_w )
  88. {
  89.     if (redalert_spriteram1[offset] != data)
  90.     {
  91.         redalert_dirtycharacter[((offset / 8) % 0x80) + 0x80] = 1;
  92.  
  93.         redalert_spriteram1[offset] = data;
  94.     }
  95. }
  96.  
  97. /***************************************************************************
  98. redalert_spriteram2_w
  99. ***************************************************************************/
  100.  
  101. WRITE_HANDLER( redalert_spriteram2_w )
  102. {
  103.     if (redalert_spriteram2[offset] != data)
  104.     {
  105.         redalert_dirtycharacter[((offset / 8) % 0x80) + 0x80] = 1;
  106.  
  107.         redalert_spriteram2[offset] = data;
  108.     }
  109. }
  110.  
  111. /***************************************************************************
  112. redalert_characterram_w
  113. ***************************************************************************/
  114.  
  115. WRITE_HANDLER( redalert_characterram_w )
  116. {
  117.     if (redalert_characterram[offset] != data)
  118.     {
  119.         redalert_dirtycharacter[((offset / 8) % 0x80)] = 1;
  120.  
  121.         redalert_characterram[offset] = data;
  122.     }
  123. }
  124.  
  125. /***************************************************************************
  126.  
  127.   Draw the game screen in the given osd_bitmap.
  128.   Do NOT call osd_update_display() from this function, it will be called by
  129.   the main emulation engine.
  130.  
  131. ***************************************************************************/
  132. void redalert_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  133. {
  134.     int offs,i;
  135.  
  136.     /* for every character in the Video RAM, check if it has been modified */
  137.     /* since last time and update it accordingly. */
  138.     for (offs = videoram_size - 1;offs >= 0;offs--)
  139.     {
  140.         int charcode;
  141.         int stat_transparent;
  142.  
  143.  
  144.         charcode = videoram[offs];
  145.  
  146.         if (dirtybuffer[offs] || redalert_dirtycharacter[charcode])
  147.         {
  148.             int sx,sy,color;
  149.  
  150.  
  151.             /* decode modified background */
  152.             if (redalert_dirtyback[offs] == 1)
  153.             {
  154.                 decodechar(Machine->gfx[0],offs,redalert_backram,
  155.                             Machine->drv->gfxdecodeinfo[0].gfxlayout);
  156.                 redalert_dirtyback[offs] = 2;
  157.             }
  158.  
  159.             /* decode modified characters */
  160.             if (redalert_dirtycharacter[charcode] == 1)
  161.             {
  162.                 if (charcode < 0x80)
  163.                     decodechar(Machine->gfx[1],charcode,redalert_characterram,
  164.                                 Machine->drv->gfxdecodeinfo[1].gfxlayout);
  165.                 else
  166.                     decodechar(Machine->gfx[2],charcode-0x80,redalert_spriteram1,
  167.                                 Machine->drv->gfxdecodeinfo[2].gfxlayout);
  168.                 redalert_dirtycharacter[charcode] = 2;
  169.             }
  170.  
  171.  
  172.             dirtybuffer[offs] = 0;
  173.  
  174.             sx = 31 - offs / 32;
  175.             sy = offs % 32;
  176.  
  177.             stat_transparent = TRANSPARENCY_NONE;
  178.  
  179.             /* First layer of color */
  180.             if (charcode >= 0xC0)
  181.             {
  182.                 stat_transparent = TRANSPARENCY_COLOR;
  183.  
  184.                 color = color_lookup[charcode];
  185.  
  186.                 drawgfx(tmpbitmap,Machine->gfx[2],
  187.                         charcode-0x80,
  188.                         color,
  189.                         0,0,
  190.                         8*sx,8*sy,
  191.                         &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  192.             }
  193.  
  194.             /* Second layer - background */
  195.             color = redalert_backcolor[offs];
  196.             drawgfx(tmpbitmap,Machine->gfx[0],
  197.                     offs,
  198.                     color,
  199.                     0,0,
  200.                     8*sx,8*sy,
  201.                     &Machine->drv->visible_area,stat_transparent,0);
  202.  
  203.             /* Third layer - alphanumerics & sprites */
  204.             if (charcode < 0x80)
  205.             {
  206.                 color = color_lookup[charcode];
  207.                 drawgfx(tmpbitmap,Machine->gfx[1],
  208.                         charcode,
  209.                         color,
  210.                         0,0,
  211.                         8*sx,8*sy,
  212.                         &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  213.             }
  214.             else if (charcode < 0xC0)
  215.             {
  216.                 color = color_lookup[charcode];
  217.                 drawgfx(tmpbitmap,Machine->gfx[2],
  218.                         charcode-0x80,
  219.                         color,
  220.                         0,0,
  221.                         8*sx,8*sy,
  222.                         &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  223.             }
  224.  
  225.         }
  226.     }
  227.  
  228.     for (i = 0;i < 256;i++)
  229.     {
  230.         if (redalert_dirtycharacter[i] == 2)
  231.             redalert_dirtycharacter[i] = 0;
  232.     }
  233.  
  234.     for (i = 0;i < 0x400;i++)
  235.     {
  236.         if (redalert_dirtyback[i] == 2)
  237.             redalert_dirtyback[i] = 0;
  238.     }
  239.  
  240.     /* copy the character mapped graphics */
  241.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  242.  
  243. }
  244.  
  245.